package com.test.cordova.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 被观察者
 */

public abstract class Observable<T> {

    public final List<T> observeList = new ArrayList<>();


    public void registerObserver(T cls){
        if (cls == null) {
            throw new NullPointerException();
        }
        synchronized (observeList) {
            if (!observeList.contains(cls)) {
                observeList.add(cls);
            }
        }
    }


    public void unRegisterAllObserver(){
        synchronized (observeList) {
            observeList.clear();
        }
    }

    public abstract void notifyObservers(Object ... objects);

    public abstract void notifyObserver(T cls,Object ... objects);

}
